Skip to content

Conversation

@jaclync
Copy link
Contributor

@jaclync jaclync commented Sep 9, 2025

For WOOMOB-1289

Summary

  • Add posLastIncrementalSyncDate column to Site table to track last incremental sync date for POS
  • Create POSSite model with conversion utilities to bridge Storage and Yosemite layers
  • Add loadSite and updateSite methods to POSCatalogPersistenceService for site management
  • Update POSCatalogIncrementalSyncService to use persisted sync date when determining modifiedAfter parameter
  • Add test coverage for site persistence and incremental sync behavior

Steps to reproduce

Just CI is sufficient, as the incremental service isn't integrated with the app yet.

Testing information

I tested that incremental sync worked after a full sync for a big site, making changes to at least one product and variation while full sync is in progress:

Task {
   do {
        let date = Date()
        let catalog = try await syncService.startFullSync(for: siteID)
        print("Full sync completed with \(catalog.products.count) products and \(catalog.variations.count) variations for siteID \(siteID)")

        try await incrementalSyncService.startIncrementalSync(for: siteID, lastFullSyncDate: date)
        print("Incremental sync completed")
    } catch {
        print("Full sync failed for siteID \(siteID) with error: \(error)")
    }
}

After all syncs were complete, I verified that posLastIncrementalSyncDate was set to the correct datetime in the site table in the sqlite database.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@jaclync jaclync changed the base branch from trunk to feat/WOOMOB-1298-incremental-sync-persistence September 9, 2025 06:13
@jaclync jaclync added type: task An internally driven task. feature: POS labels Sep 9, 2025
@jaclync jaclync added this to the 23.3 milestone Sep 9, 2025
@jaclync jaclync changed the title Persist incremental sync date in Site for POS catalog sync [Local Catalog] Incremental sync: persist incremental sync date in Site storage entity Sep 9, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 9, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16108-f625bab
Version23.2
Bundle IDcom.automattic.alpha.woocommerce
Commitf625bab
Installation URL3ue8ostq494jg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@jaclync jaclync changed the title [Local Catalog] Incremental sync: persist incremental sync date in Site storage entity [Local Catalog] Incremental sync: persist incremental sync date in Site table Sep 9, 2025
@jaclync jaclync requested a review from joshheald September 9, 2025 06:53
@jaclync jaclync changed the title [Local Catalog] Incremental sync: persist incremental sync date in Site table [Local Catalog] Incremental sync: persist incremental sync date in Site storage entity Sep 9, 2025
Copy link
Contributor

@joshheald joshheald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to check how this works a little more with site credential login.

Here's what I think happens:

  1. Log in with one site's credentials and sync – everything gets persisted to the -1 site ID
  2. Logout – I don't think the site is deleted
  3. Log in with a different site's credentials – incremental sync will happen, based on the date stored here.
  4. All the wrong data will still be stored.

If we delete the site on logout, none of this is an issue... but I don't think that will happen.

I want to check what happens with the user defaults site-specific storage too.

static func createSiteTable(_ db: Database) throws {
try db.create(table: "site") { siteTable in
siteTable.primaryKey("id", .integer).notNull()
siteTable.column("posLastIncrementalSyncDate", .datetime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid mentioning POS in the database layer, until we're sure it's just for POS.

If the store management part of the app starts using this database, we'll want to keep sync working properly. Realistically, I think that means having a single sync controller, not separate ones for POS and the main app. Especially for shared entities such as products/variations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, renamed posLastIncrementalSyncDate to lastCatalogIncrementalSyncDate in f625bab.

Comment on lines +167 to +168
let persistedSite = PersistedSite(from: site)
try persistedSite.update(db)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps PersistedSite needs MutableFetchableRecord?

Seems a little odd to fetch the site and never use it, just replace it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little odd to fetch the site and never use it, just replace it.

Did you mean fetching the site from the database? L167 is converting a POSSite to PersistedSite without going through the database.

These two lines are to update the Site in the database from a given POSSite. Feel free to share better ways to do update an existing record.

Comment on lines +11 to +13
private var db: GRDBDatabaseConnection {
grdbManager.databaseConnection
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Base automatically changed from feat/WOOMOB-1298-incremental-sync-persistence to trunk September 10, 2025 06:28
@jaclync
Copy link
Contributor Author

jaclync commented Sep 10, 2025

If we delete the site on logout, none of this is an issue... but I don't think that will happen.

Sounds like a similar discussion point to the thread in #16100 (comment). Let's continue the discussion there.

I want to check what happens with the user defaults site-specific storage too.

On logout (AuthenticatedState.willLeave), a reset action is dispatched to reset the store settings which deletes the plist file:

let resetGeneralStoreSettings = AppSettingsAction.resetGeneralStoreSettings

@jaclync
Copy link
Contributor Author

jaclync commented Sep 11, 2025

Merging now to make dependent work easier (integrating the incremental sync service to sync coordinator). Feel free to leave suggestions and I'll respond later.

@jaclync jaclync merged commit 801d7c9 into trunk Sep 11, 2025
14 checks passed
@jaclync jaclync deleted the feat/WOOMOB-1289-persist-incremental-sync-date branch September 11, 2025 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: POS type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants